package com.webapp.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.webapp.model.CustomerRepModel;
import com.webapp.model.User;

/**
 * Servlet implementation class UpdateUser
 */
public class UpdateUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	HttpSession session = request.getSession();
	String firstname = request.getParameter("FIRSTNAME");
	String lastname = request.getParameter("LASTNAME");
	int ssn = Integer.parseInt(request.getParameter("SSN"));
	int rating = Integer.parseInt(request.getParameter("RATING"));
	int id = Integer.parseInt(request.getParameter("ID"));
	String password = request.getParameter("PASSWORD");
	String address = request.getParameter("ADDRESS");
	String city = request.getParameter("CITY");
	String state = request.getParameter("State");
	String email = request.getParameter("EMAIL");
	int zip = Integer.parseInt(request.getParameter("ZIP"));
	
	User theUser = (User)session.getAttribute("UserEdit");
	theUser.setAddress(address);
	theUser.setCity(city);
	theUser.setEmail(email);
	theUser.setFirstName(firstname);
	theUser.setLastName(lastname);
	theUser.setPassword(password);
	theUser.setRating(rating);
	theUser.setSSN(ssn);
	theUser.setState(state);
	theUser.setZip(zip);
	
	CustomerRepModel crm = new CustomerRepModel();
	if(crm.editCustomer(theUser))
		response.sendRedirect("EmployeeLanding.jsp");
	else 
		response.sendRedirect("Error.jsp");
	}
	

}
